<?php

namespace app\admin\controller;

use app\common\wechat\TPWechat;

class WechatController
{
    public function index()
    {
        echo 'wechat';
    }

    public function wechatServer()
    {
        $msg = "尊敬的客户您好，今年的大闸蟹兑换已开始，您可根据扫码后进入公众号兑换流程进行操作，详询可致电0512-52551045。";
        $weObj = new TPWechat(config('wechat'));
        $weObj->valid(); //明文或兼容模式可以在接口验证通过后注释此句，但加密模式一定不能注释，否则会验证失败
        $type = $weObj->getRev()->getRevType();
        switch ($type) {
            case TPWechat::MSGTYPE_TEXT:
                $weObj->text($msg)->reply();
                break;
            case TPWechat::MSGTYPE_EVENT:

                $weObj->text($msg)->reply();
                break;
            case TPWechat::MSGTYPE_IMAGE:
                break;
            default:
                $weObj->text("help info")->reply();
        }
    }

    public function createMenu()
    {
        $weObj = new TPWechat(config('wechat'));
        // $weObj->valid(); //明文或兼容模式可以在接口验证通过后注释此句，但加密模式一定不能注释，否则会验证失败
        if ($weObj->createMenu(config('wechat_menu'))) {
            echo 'OK';
        } else {
            echo $weObj->errCode;
            echo "<br>";
            echo $weObj->errMsg;
        }
    }
}
